<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>表单注册和验证</title>
    <script type="text/javascript">
        
        function showEnter(){
           alert("尊敬的客户，欢迎您光临本店");
        }

        function showLeave(){

              alert("欢迎下次光临!");
        }

        //页面加载事件时调用函数
        window.onload = showEnter;

        //页面关闭事件触发时调用函数
        window.onbeforeunload = showLeave;



        function isEmail(theStr)
        {
             var atindex = theStr.indexOf('@');
             var dotindex = theStr.indexOf('.',atindex);
             var flag = true;
             thesub = theStr.substring(0,dotindex + 1);

             if((atindex < 1) || (atindex != theStr.lastIndexOf('@')) || (dotindex < atindex + 2) || (theStr.length <= thesub.length))
             {
                 flag = false;
             }else
             {
                 flag = true;
             }
             return(flag);
        }

        function check()
        {
            fr = document.form1;
            if(fr.uid.value == "") 
            {
              alert("用户ID必须要填写！");
               fr.uid.focus();
               return false;
            }
            if((fr.psw1.value != "") || (fr.psw2.value != ""))
            {
              if(fr.psw1.value != fr.psw2.value)
              {
                  alert("密码不一致，请重新输入并验证密码！");
                  fr.psw1.focus();
                  return false;
              }
          }
          else{
               alert("密码不能为空！");
               fr.psw1.focus();
               return false;
          }
          if(fr.gender.value == "")
          {
             alert("性别必须要填写!");
             fr.name.focus();
             return false;
          }

           if(fr.email.value != "")
           {
               if(!isEmail(fr.email.value))
               {
                   alert("请输入正确的邮件名称");
                   fr.email.focus();
                  return false;
               }
           }
          fr.submit();
        }
    </script>
</head>
<body>
    <form name="form1"  id="form1" method="post" action="reg2.jsp">
    <table border="1"  align="center" width="350">
        <tr align="middle"><th colSpan=2 height=24>新用户注册</th></tr>
        <tr>
            <td width="40%">
                <b>用&nbsp;户&nbsp;名</b></td>
            <td width="60%"> <input type="text" name="uid" size="30" maxlength="10"></td>
        </tr>

        <tr>
            <td><b>性&nbsp;&nbsp;&nbsp;&nbsp;别</b>:</td>
            <td>
             <input type="radio" checked="CHECKED" name="gender" value="boy" >男孩
             <input type="radio" name="gender" value="girl">女孩
            </td>
        </tr>
        <tr>
              <td><B>密&nbsp;&nbsp;&nbsp;&nbsp;码</B>:</td>
              <td><input type="password" name="psw1" size="32"></td>
        </tr>

        <tr>
             <td><B>确认密码</B></td>
             <td><input type="password" name="psw2" size="32"></td>     
        </tr>

        <tr>
             <td><B>密码问题</B></td>
             <td><input type="question" name="text" size="30"></td>     
        </tr>

        <tr>
             <td><B>问题答案</B></td>
             <td><input type="text" name="answer"  size="30"></td>
        </tr>

        <tr>
             <td><B>email</B></td>
             <td><input type="text" name="email" size="30" maxlength="50"></td>
        </tr>
        <tr>
             <td><B>联系电话</B></td>
             <td><input type=" text" name="tel" size="30" maxlength="50"></td>
        </tr>

        <tr>
            <td><b>职&nbsp;&nbsp;&nbsp;&nbsp;业</b>:</td>
            <td>  <select   name="career"  class="input1">
                   <option  value="student"  selected="selected">学生</option>
                   <option  value="teacher">老师</option>
                   <option  value="worker">工人</option>
                   <option  value="famer">农民</option>
                   <option  value="business">商人</option>
                   </select> 
            </td>
        </tr>
         <tr>
            <td></td>
            <td>
                   <input type="submit" value="注册" name=submit onclick="return check()">
                  <input type="reset"  value="清除" name=submit2></option>
            </td>
         </tr> 
       </table>
    </form>
</body>
</html>







